<template>
  <div class="comment-reply">
    <!-- 头部信息 -->
    <van-nav-bar :title="`${comment.reply_count}条回复`" fixed>
      <template #left>
        <van-icon name="cross" @click="$emit('close')" />
      </template>
    </van-nav-bar>
    <!-- 头部信息 -->

    <!-- 当前评论项 -->
    <CommentItem :comment="comment" />
    <!-- 当前评论项 -->

    <!-- 所有回复 -->
    <van-cell title="所有回复"></van-cell>
    <CommentList :articleId="comment.com_id" type="c" :list="commentList" />
    <!-- 所有回复 -->

    <!-- 底部区域 -->
    <div class="article-bottom">
      <van-button
        class="comment-btn"
        type="default"
        round
        size="small"
        @click="isPostShow = true"
        >写评论</van-button
      >
    </div>
    <!-- 底部区域 -->

    <!-- 发布评论 -->
    <van-popup v-model="isPostShow" position="bottom">
      <CommnetPost
        :target="comment.com_id"
        :articleId="articleId"
        @post-success="onPostSucces"
      />
    </van-popup>
    <!-- 发布评论 -->
  </div>
</template>

<script>
import CommentItem from './comment-item.vue'
import CommentList from './comment-list.vue'
import CommnetPost from './commnet-post.vue'
export default {
  data() {
    return {
      isPostShow: false,
      commentList: [] // 评论的回复列表
    }
  },
  components: { CommentItem, CommentList, CommnetPost },
  props: {
    comment: {
      type: Object,
      required: true
    },
    articleId: {
      type: [String, Number],
      required: true
    }
  },
  methods: {
    onPostSucces(comment) {
      // 把发布成功的评论放到列表顶部
      this.commentList.unshift(comment.new_obj)
      // 更新评论的回复数量
      this.comment.reply_count++
      // 关闭发布的弹出层
      this.isPostShow = false
    }
  }
}
</script>

<style lang="less" scoped>
.article-bottom {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  box-sizing: border-box;
  height: 88px;
  border-top: 1px solid #d8d8d8;
  background-color: #fff;
  .comment-btn {
    width: 350px;
    height: 60px;
    border: 2px solid #eeeeee;
    font-size: 30px;
    line-height: 46px;
    color: #a7a7a7;
  }
}
</style>
